package com.qc31.monitorlib.color

import android.graphics.Color
import android.widget.ImageView
import androidx.core.view.isVisible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.qc31.monitorlib.R


/**
 *@Author Jasper
 *@Time 2021/11/30 11:19
 *@Desc
 */
class ColorAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_color_circlr) {
    var index = 0
    override fun convert(holder: BaseViewHolder, item: String) {
        val colorView = holder.getView<ColorPanelView>(R.id.cpv_color_panel_view)
        colorView.color = Color.parseColor(item)
        val checkView = holder.getView<ImageView>(R.id.cpv_color_image_view)
        val isCheck = holder.layoutPosition == index
        checkView.isVisible = isCheck
        checkView.setImageResource(if (isCheck) R.mipmap.cpv_preset_checked else 0)
    }
}